package com.shoplink.view;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.widget.EditText;

public class IPEditTextView extends EditText {

	private TextChangeListener listener;

	interface TextChangeListener {
		public void onTextChange(CharSequence s, int start, int before,
				IPEditTextView editText);
	}

	public void setTextChangeListener(TextChangeListener listener) {
		this.listener = listener;
	}

	public IPEditTextView(Context context) {
		super(context);
		addTextChangedListener(textWatcher);
	}

	public IPEditTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		addTextChangedListener(textWatcher);
	}

	TextWatcher textWatcher = new TextWatcher() {

		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
			if (listener != null) {
				listener.onTextChange(s, start, before, IPEditTextView.this);
			}
		}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {

		}

		@Override
		public void afterTextChanged(Editable s) {
			// TODO Auto-generated method stub
		}
	};

}
